package org.baixin.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;

import org.baixin.entity.base.IdEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 
 * 
 * 角色
 * 
 * @author slaton.wu@gmail.com
 * @version 1.0
 * @created 2011-6-11 上午08:57:38
 */
@Entity(name="pm_role")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role extends IdEntity {
	
	/**
	 * 角色英文名称
	 * 全系统必须唯一
	 */
	private String roleEname;
	
	/**
	 * 中文名
	 */
	private String roleCname;
	
	/**
	 * 角色状态
	 */
	private String status;
	
	/**
	 * 具有此角色的用户集合
	 */
	private List<User> users;
	
	/**
	 * 此角色所有资源
	 */
	private List<Resource> reses;
	
	/**
	 * 角色属于哪些组织
	 */
	private List<Organization> orgs;
	
	/**
	 * 角色拥有的操作
	 */
	private List<Operate> operates;
	
	
	
	/**
	 * 返回 operates 的值
	 * @return operates
	 */
	@ManyToMany(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
	@JoinTable(name = "pm_role_operate", joinColumns = { @JoinColumn(name = "roleid") }, inverseJoinColumns = { @JoinColumn(name = "operid") })
	@OrderBy("id")
	@Fetch(FetchMode.SUBSELECT)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Operate> getOperates() {
		return operates;
	}

	/**
	 * 设置 operates 的值
	 * @param operates
	 */
	
	public void setOperates(List<Operate> operates) {
		this.operates = operates;
	}

	/**
	 * 返回 orgs 的值
	 * @return orgs
	 */
	@ManyToMany(cascade=CascadeType.REFRESH,mappedBy="roles")  
	public List<Organization> getOrgs() {
		return orgs;
	}

	/**
	 * 设置 orgs 的值
	 * @param orgs
	 */
	
	public void setOrgs(List<Organization> orgs) {
		this.orgs = orgs;
	}

	/**
	 * 返回 reses 的值
	 * @return reses
	 */
	@ManyToMany(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
	@JoinTable(name = "pm_role_res", joinColumns = { @JoinColumn(name = "roleid") }, inverseJoinColumns = { @JoinColumn(name = "resid") })
	@OrderBy("id")
	@Fetch(FetchMode.SUBSELECT)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Resource> getReses() {
		return reses;
	}

	/**
	 * 返回 roleCname 的值
	 * @return roleCname
	 */
	
	public String getRoleCname() {
		return roleCname;
	}

	/**
	 * 返回 roleEname 的值
	 * @return roleEname
	 */
	
	public String getRoleEname() {
		return roleEname;
	}

	/**
	 * 返回 status 的值
	 * @return status
	 */
	
	public String getStatus() {
		return status;
	}

	/**
	 * 返回 users 的值
	 * @return users
	 */
	@ManyToMany(cascade = CascadeType.REFRESH, mappedBy = "roles", fetch = FetchType.LAZY)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<User> getUsers() {
		return users;
	}

	/**
	 * 设置 reses 的值
	 * @param reses
	 */
	
	public void setReses(List<Resource> reses) {
		this.reses = reses;
	}

	/**
	 * 设置 roleCname 的值
	 * @param roleCname
	 */
	
	public void setRoleCname(String roleCname) {
		this.roleCname = roleCname;
	}

	/**
	 * 设置 roleEname 的值
	 * @param roleEname
	 */
	
	public void setRoleEname(String roleEname) {
		this.roleEname = roleEname;
	}

	/**
	 * 设置 status 的值
	 * @param status
	 */
	
	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 * 设置 users 的值
	 * @param users
	 */
	
	public void setUsers(List<User> users) {
		this.users = users;
	}
	
	
	

}
